//1004.最大连续1的个数
#include<iostream>
#include<vector>
using namespace std;



int longestOnes(vector<int>& nums,int k){
    //定义左右指针
    int left = 0, right = 0;
    int maxlen = 0;
    int zero = 0;

    while(right<nums.size()){
        if(nums[right]==0){
            zero++;
        }
        if(zero>k){
            while(nums[left]){
                left++;
            }
            zero--;
            left++;
        }

        maxlen = max(maxlen, right - left + 1);

        right++;
    }

    return maxlen;
}

int main(){
    int k=2;
    vector<int> nums = {1,1,1,0,0,0,1,1,1,1,0};

    int maxlen = longestOnes(nums, k);
    cout << maxlen;
    return 0;
}